package com.example.jeong.yuejian10.Model;


import com.example.jeong.yuejian10.Bean.ActivityBean;
import com.example.jeong.yuejian10.Bean.AttentionBean;
import com.example.jeong.yuejian10.Bean.ClubBean;
import com.example.jeong.yuejian10.Bean.CourseBean;
import com.example.jeong.yuejian10.Bean.IsAttentionBean;
import com.example.jeong.yuejian10.Bean.VideoBean;
import com.example.jeong.yuejian10.Listener.RetrofitListener;
import com.example.jeong.yuejian10.Service.ClubService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.jeong.yuejian10.constant.Constant.BASE_URL;


public class ClubModel {

    private Retrofit retrofit;
    public ClubModel(){
        //创建实例
        retrofit =new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    //俱乐部列表
    public void getClublist(final RetrofitListener listener){
        ClubService clubService = retrofit.create(ClubService.class);
        Call call = clubService.getClublist();
        Callback<List<ClubBean>> callback = new Callback<List<ClubBean>>() {
            @Override
            public void onResponse(Call<List<ClubBean>> call, Response<List<ClubBean>> response) {
                List<ClubBean> clubBeen = response.body();
                listener.onSuccess(clubBeen);
            }
            @Override
            public void onFailure(Call<List<ClubBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);

    }



    //俱乐部详情
    public Call<ClubBean> getClubinfo(int c_id){
        ClubService clubService = retrofit.create(ClubService.class);
        return clubService.getClubinfo(c_id);
    }

    public void getClubactivitys(int c_id,final RetrofitListener listener){

        ClubService clubService = retrofit.create(ClubService.class);
        Call call = clubService.getClubactivitys(c_id);
        System.out.print(c_id);
        Callback<List<ActivityBean>> callback = new Callback<List<ActivityBean>>() {
            @Override
            public void onResponse(Call<List<ActivityBean>> call, Response<List<ActivityBean>> response) {
                List<ActivityBean> activityBeen = response.body();
                listener.onSuccess(activityBeen);
            }
            @Override
            public void onFailure(Call<List<ActivityBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);

    }

    //俱乐部课程列表
    public void getClubcourselist(int c_id,final RetrofitListener listener){

        ClubService clubService = retrofit.create(ClubService.class);
        Call call = clubService.getClubcourselist(c_id);
        System.out.print(c_id);
        Callback<List<CourseBean>> callback = new Callback<List<CourseBean>>() {
            @Override
            public void onResponse(Call<List<CourseBean>> call, Response<List<CourseBean>> response) {
                List<CourseBean> courseBeen = response.body();
                listener.onSuccess(courseBeen);
            }
            @Override
            public void onFailure(Call<List<CourseBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);

    }

    //俱乐部视频列表
    public void getClubvideolist(int c_id,final RetrofitListener listener){

        ClubService clubService = retrofit.create(ClubService.class);
        Call call = clubService.getClubvideolist(c_id);
        System.out.print(c_id);
        Callback<List<VideoBean>> callback = new Callback<List<VideoBean>>() {
            @Override
            public void onResponse(Call<List<VideoBean>> call, Response<List<VideoBean>> response) {
                List<VideoBean> videoBeen = response.body();
                listener.onSuccess(videoBeen);
            }
            @Override
            public void onFailure(Call<List<VideoBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);

    }

    //搜索J俱乐部
    public Call<List<ClubBean>> searchClub(String c_name){
        ClubService clubService = retrofit.create(ClubService.class);
        return clubService.searchClub(c_name);
    }

    //判断是否关注
    public Call<IsAttentionBean> getIsCollected(int u_id, int select_id, String flag){
        ClubService clubService=retrofit.create(ClubService.class);
        return clubService.getIsCollected(u_id, select_id, flag);
    }


    //用户关注培训接口
    public Call<AttentionBean> userCollectClub(int u_id, int c_id){
        ClubService clubService=retrofit.create(ClubService.class);
        return clubService.userCollectClub(u_id,c_id);
    }


}

